package com.it.jdbc.utils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * 使用工具类进行数据的查询
 */
public class JdbcDemo03 {
    public static void main(String[] args) throws Exception{
        //1.获取数据库连接
        Connection connection = JDBCUtils.getConnection();
        //2.获取statement
        Statement statement = connection.createStatement();
        //3.查询所有数据
        String sql = "select * from account";
        //调用工具类
        //PreparedStatement preparedStatement = JDBCUtils.getPreparedStatement(sql);
        //执行sql
        ResultSet resultSet = statement.executeQuery(sql);
        //获取结果
        while(resultSet.next()){
            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");
            double money = resultSet.getDouble("money");

            System.out.println(id+" "+name+" "+money);
        }
        //关闭资源
        JDBCUtils.close(resultSet,statement,connection);
    }

}
